<template>
    <view>
        <view class="textarea">
          <u--textarea v-model="content" placeholder="请输入内容" confirmType="done"></u--textarea>
        </view>
        <Upload v-model="pictures" @delete="deletePic" name="1" multiple :maxCount="10">
        </Upload>
        <u-button @click="submit">发表</u-button>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                pictures: [],
                content: '',
                eventChannel: () => {}
            }
        },
        methods: {
            // 删除图片
            deletePic(event) {
                this[`fileList${event.name}`].splice(event.index, 1)
            },
            submit() {
                this.$http.post('/news', {
                    pictures: this.pictures ,
                    content: this.content
                }).then((res) => {
                    this.eventChannel.emit('publish', res.data)
                    this.$nav.switchTab('/pages/market/market')
                })
                
            },
        },
        onLoad() {
            // #ifdef APP-NVUE
              this.eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
              // #endif
              // #ifndef APP-NVUE
              this.eventChannel = this.getOpenerEventChannel();
              // #endif
        }
    }
</script>

<style scoped>
.textarea{
  margin-bottom: 20rpx;
}
</style>
